﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KiDS_Projekat
{
	/// <summary>
	/// Komanda koja prima push zahtev od drugog serventa i upisuje sve poslate temperature u Node
	/// </summary>
	public class PushDataCommand : Command
	{

		private string _command;
		private Node _myNode;
		public unsafe PushDataCommand(SOCKET socket, string command, Node myNode)
		 : base(socket){
			 _command = CommandFactory.NormalizeLocation(command);
			 _myNode = myNode;
		}

		public override void DoCommmand()
		{
			Program.Terminal.Print(_command);
			string[] temps = _command.Split(';');
			foreach(var temp in temps){
				var param = temp.Split(':');
				_myNode.CollectTemperature(param[0], Double.Parse(param[1])/100);
			}

			Native.closesocket(_socket);
		}
	}
}
